<?php
/**
 * Created by PhpStorm.
 * User: pc
 * Date: 2017/4/6
 * Time: 10:42
 */

namespace Tiger\Api\Traits;
use Symfony\Component\HttpKernel\Exception\ConflictHttpException;
use Dingo\Api\Exception\StoreResourceFailedException;
use Dingo\Api\Exception\UpdateResourceFailedException;
use Dingo\Api\Exception\ResourceException;
use Dingo\Api\Exception\DeleteResourceFailedException;
use Tiger\Api\Utils\TigerException;
trait ApiResponse
{
    public  function apiReturn($model,$transformerClassName)
    {
        return $this->response->item($model,$transformerClassName);
    }

    public  function apiReturns($models,$transformerClassName)
    {
        return $this->response->collection($models,$transformerClassName);
    }

    public  function apiReturnSuccess()
    {
        return $this->successResponse('success');
    }

    public  function apiReturnFail()
    {
        return $this->successResponse('fail');
    }

    public  function apiReturnPage($models,$transformerClassName)
    {
        return $this->response->paginator($models,$transformerClassName);
    }

    public  function apiReturnNoContent()
    {
        return $this->response->noContent();
    }

    public  function apiReturnNoPermission()
    {
        $this->response->errorForbidden();
    }

    public  function apiReturnDebugInfo($info)
    {
        throw new ConflictHttpException($info);
    }

    public  function  apiRestfulDeleteError($info)
    {
        throw new DeleteResourceFailedException($info);
    }

    public  function  apiRestfulShowError($info)
    {
        throw new ResourceException($info);
    }


    public  function  apiRestfulStoreError($info)
    {
        throw new StoreResourceFailedException($info);
    }


    public  function  apiRestfulUpdateError($info)
    {
        throw new UpdateResourceFailedException($info);
    }

    public  function  apiRestfulIndexError($info)
    {
        throw new ResourceException($info);
    }

    public  function apiReturnSingle($message)
    {
        $response = array(
            'data' => $message,
        );
        return response()->json($response);
    }



}